#include "main.h"

time_display::time_display(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::time_display)
{
    ui->setupUi(this);
    ui->dateTimeEdit->setDisplayFormat("yyyy-M-d hh:mm:ss");
    timer=new QTimer();
    QObject:: connect( timer, SIGNAL(timeout()), SLOT(timeDone()) );

    ui->dateTimeEdit->setButtonSymbols(QAbstractSpinBox::PlusMinus);
    write_protect(true);
}


void time_display::write_protect(bool b)
{
    ui->dateTimeEdit->setReadOnly(b);
    if(b) timer->start( 1000 );
    else  timer->stop();
}

time_display::~time_display()
{

    delete ui;
    delete timer;
}

void time_display::timeDone()
{
    ui->dateTimeEdit->setDateTime(QDateTime::currentDateTime());

}
